package com.cssw.fyzb.core.dao.video;

import com.cssw.fyzb.core.model.dodb.CmfVideoReport;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.Map;

/**
 * @Author: YangYiQun
 * @Date: 2020/10/10 15:10
 */
@Repository
public class VideoReportDaoImpl implements VideoReportDao {

    /**
     * 查询菜单列表
     *
     * @param page
     * @param limit
     * @param param
     * @return
     */
    public Page<CmfVideoReport> list(int page, int limit, Map param) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select * from cmf_video_report");
        sqlParse.addSQL(" order by report_id desc ");
        return CmfVideoReport.dao.paginate(page, limit, sqlParse);
    }

    public CmfVideoReport findOne(Long reportId){
        return CmfVideoReport.dao.findById(reportId);
    };

    public  void updateStatus(Long reportId, String status){
        CmfVideoReport cmfVideoReport = new CmfVideoReport();
        cmfVideoReport.setReportId(reportId);
        cmfVideoReport.setStatus(status);
        cmfVideoReport.setUpdateTime(new Date());
        cmfVideoReport.update();
    }

    @Override
    public Long save(Long fromUserId, Long toUserId, Long videoId) {
        CmfVideoReport cmfVideoReport = new CmfVideoReport();
        cmfVideoReport.setFromUserId(fromUserId);
        cmfVideoReport.setToUserId(toUserId);
        cmfVideoReport.setVideoId(videoId);
        cmfVideoReport.setStatus(CmfVideoReport.STATUS_INIT);
        cmfVideoReport.setCreateTime(new Date());
        cmfVideoReport.save();
        return cmfVideoReport.getReportId().longValue();
    }
}
